#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# Magpie - an open source discussion forum system.
#
# Copyright (C) 2009 The Magpie Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from ajiaojr.commons.django.shortcuts import render_to_response

from ajiaojr.magpie import models
from ajiaojr.magpie.views import build_template_params

from django.utils.translation import ugettext as _

def bank_enabled_required(func):
  """Decorator to ensure that the bank service is enabled
  """
  def bank_enabled_wrapper(request, *args, **kwds):
    club_config = models.ClubConfig.get_instance()
    if not club_config.is_bank_enabled and not request.admin_mode:
      return HttpResponseForbidden("<h1>Access Denied</h1>")
    return func(request, *args, **kwds)
  return bank_enabled_wrapper

@bank_enabled_required
def index(request):
  p = build_template_params(_('Account Overview'), '/', request.user)
  return render_to_response(request, 'services/bank/index.html', p)
